<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>天气案例_深度监视</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>

<body>

    <div id="root">
        <h2>天气很{{info}}</h2>
        <button @click="changeWeather">切换天气</button>
        <hr>
        <h3>a的值是:{{number.a}}</h3>
        <button @click="number.a++">a+1</button>
        <h3>b的值是:{{number.b}}</h3>
        <button @click="number.b++">b+1</button>
    </div>

    <script type="text/javascript">
        const vm = new Vue({
            el: '#root',
            data: {
                isHot: true,
                number: {
                    a: 1,
                    b: 1
                }
            },
            computed: {
                info() {
                    return this.isHot ? '炎热' : '寒冷'
                }
            },
            methods: {
                changeWeather() {
                    this.isHot = !this.isHot
                }
            },
            // 监视的第一种写法
            watch: {
                // 监视多级结构中某个属性的变化
                isHot: {
                    // handler调用：当isHot发生改变时
                    handler(newValue, oldValue) {
                        console.log('isHot被修改', newValue, oldValue)
                    }
                },
                // 监视多级结构中所有属性的变化
                'number': {
                    deep: true, //开启深度监视,可以监视多层级
                    handler() {
                        console.log('number被修改了')
                    }
                },
            }
        })


    </script>

</body>

</html>